/*
 * @Author: your name
 * @Date: 2021-08-02 01:30:11
 * @LastEditTime: 2021-08-02 15:40:19
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \aircityinit\src\tools\Event.js
 */
import store from '../store'
function OSnow() {
  var agent = navigator.userAgent.toLowerCase();
  var isMac = /macintosh|mac os x/i.test(navigator.userAgent);
  if (agent.indexOf("win32") >= 0 || agent.indexOf("wow32") >= 0) {
    return "pc";
  }
  if (agent.indexOf("win64") >= 0 || agent.indexOf("wow64") >= 0) {
    return "pc";
  }
  if (isMac) {
    return "mac";
  }
}

const OnEvent = async (e) => {
  console.log(e);
  // 判断是否为左键点击的交互
  if (e.eventtype === "LeftMouseButtonClick") {
    const res = await __g.coord.world2Screen(...e.MouseClickPoint);
    const position = res
      ? OSnow() === "mac"
        ? [res.screenPosition[0] / 2, res.screenPosition[1] / 2]
        : res.screenPosition
      : [0, 0];
    console.log(position, "position");
    // console.log(e, 'e');
    if (e.Type === "tag") {

    }
    if (e.Type === "Custom_Tag") {
      let tagArr = localStorage.getItem("tagArr");
      tagArr = JSON.parse(tagArr)
      __g.tag.focus(e.Id).then(res => {
        let item = tagArr.filter(v => {
          return v.id === e.Id
        })
        tagArr.forEach(v => {
          if (v.id === e.Id) {
            if (v.show == 0) { // 1代表弹窗是关闭的
              v.show = 1;
              store.commit("positionPOI", []);
            } else {
              v.show = 0;
              store.commit("positionPOI", position);
              store.commit('dialogInfo', v)
            }
          }
        })
        console.log(item, 'item');
        const { coordinate, text, show } = item[0];
        let page = HostConfig.AbsolutePath + `/int_custom_tag.html?title=${text}&show=${show}`;
        console.log(page, 'page');
        let contentWeb = new WebUIData(page, 220, 52);
        let popupWeb = new WebUIData(HostConfig.AbsolutePath + `/int_popup.html?title=${text}&id=${e.Id}`, 600, 480);
        let pivot = [0.5, 0.5];
        let range = [1, 5000];
        let o = new CustomTagData(e.Id, coordinate, contentWeb, popupWeb, pivot, range);
        // setTimeout(() => {
          __g.ctag.update(o).then(res => {
            localStorage.setItem("tagArr", JSON.stringify(tagArr))
          });
        // }, 1000)


      });
    }
  }

  if (e.eventtype === "CameraTourFinished") {
    console.log("导览播放结束");
  }
};
export default OnEvent;
